package project.layer.agents;


import framework.events.EventBroker;
import project.data.DropOffIntention;
import project.events.packageEvents.PackageDeliveredEvent;
import project.events.packageEvents.PackagePickedEvent;
import project.layer.ant.AntLayer;
import project.layer.ant.FeasibilityAnt;
import project.layer.physical.DropOffPoint;
import project.layer.physical.Package;
import project.layer.physical.PackagePoint;


public class DropOffPointAgent extends PackagePointAgent {

	public DropOffPointAgent(int packageID){
		super(packageID);
	}

	
	public boolean acceptPackage(Package pdpPackage){
		if( ((DropOffPoint)getDevice().getPhysicalEntity()).hasPackage() || getPackageID() != pdpPackage.getId()){
			return false;
		}
		else{
			((DropOffPoint)getDevice().getPhysicalEntity()).acceptPackage(pdpPackage);
			EventBroker.getEventBroker().notifyAll(new PackageDeliveredEvent(pdpPackage.getId()));
			return true;
		}
	}
	
	public boolean acceptOrRejectIntention(DropOffIntention intention){
		// in fact, this method only checks whether the package would be at the right destination if delivered
		
		// accept if the intention has the right package to deliver
		if(intention.getPackageID() == getPackageID()){
			if(hasIntention()){
				AntLayer.getInstance().unregisterEvaporableData(getCurrentIntention());			
			}
			// 3 cases possible (each uses the same function):
			// set first intention/confirm previous intention/accept intention from other sending agent
			setCurrentIntention(intention);
			return true;	

		}
		else{
			return false;
		}
	}
	


	@Override
	public boolean isDropOffPointAgent(){
		return true;
	}
	
	private DropOffPoint getDropOffPoint(){
		return ((DropOffPoint) getDevice().getPhysicalEntity());
	}
	
	@Override
	protected void sendFeasibilityAntIfNecessary() {
		
	}
	
	protected void sendFeasibilityAnt() {
		
	}

//	private void setDropOffPoint(DropOffPoint dropOffPoint) {
//		this.dropOffPoint = dropOffPoint;
//	}

//	@Override
//	public DropOffPoint getPackagePoint() {
//		return dropOffPoint;
//	}
	
}
